<template>
  <div class="lab_reference_wrapper">
    <!-- 主页 -->
    <div class="main_page">
      <div class="search_part">
        <el-form label-width="100px">
          <el-row type="flex" align="middle">
            <el-col :span="6" v-for="item in formColumns" :key="item.prop">
              <el-form-item :label="item.label" :prop="item.prop" style="margin: 0">
                <el-select
                  v-if="item.ele === 'select'"
                  size="mini"
                  v-model="formData[item.prop]"
                  @change="onSearchSelectChange"
                >
                  <el-option v-for="it in item.options" :key="it.value" :value="it.value" :label="it.label"></el-option>
                </el-select>
                <el-select v-if="item.ele === 'selectMut'" size="mini" multiple v-model="formData[item.prop]">
                  <el-option v-for="it in item.options" :key="it.value" :value="it.value" :label="it.label"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col style="margin-left: 12px; display: flex" :span="12">
              <el-button type="primary" size="mini" icon="el-icon-search" @click="handleSearch()">查询</el-button>
              <el-button size="mini" icon="el-icon-refresh" @click="handleReset()">重置</el-button>
              <el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAdd()">新增</el-button>
              <el-button type="primary" size="mini" @click="handleDownLoad()">下载导入模板</el-button>
              <el-upload
                action
                style="margin-left: 8px"
                :http-request="handleImportEmbeddedEncoding"
                :file-list="fileList"
                :show-file-list="false"
              >
                <el-button type="primary" size="mini" :loading="importLoading" style="margin-right: 8px">
                  导入
                </el-button>
              </el-upload>
              <el-button type="primary" size="mini" @click="handleDownLoadData()">导出</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="table_part">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="使用中" name="0">
            <el-table :data="tableDataOne" @select="handleTableOneSelect">
              <el-table-column fixed label="#" align="center" width="50" type="index"></el-table-column>
              <el-table-column fixed type="selection" width="55" align="center"> </el-table-column>
              <el-table-column fixed label="操作" align="center">
                <template v-slot="{ row }">
                  <i class="el-icon-edit" @click="handleEdit(row)" style="margin-right: 12px"></i>
                  <i class="el-icon-delete" @click="handleDelete(row)"></i>
                </template>
              </el-table-column>
              <el-table-column label="中心编号" align="center" prop="coreCode"></el-table-column>
              <el-table-column label="中心名称" align="center" prop="coreName"></el-table-column>
              <el-table-column label="实验室编号" align="center" prop="labCode" width="120"></el-table-column>
              <el-table-column label="实验室名称" align="center" prop="labName" width="120"></el-table-column>
              <el-table-column label="模块名称编码" align="center" prop="moduleCode" width="120"></el-table-column>
              <el-table-column label="模块名称" align="center" prop="moduleName"></el-table-column>
              <el-table-column label="检查项编码" align="center" prop="checkCode" width="120"></el-table-column>
              <el-table-column label="检测项" align="center" prop="checkProName"></el-table-column>
              <el-table-column label="性别" align="center" prop="sex">
                <template v-slot="{ row }">
                  <span v-if="row.sex === 0">未知</span>
                  <span v-if="row.sex === 1">男</span>
                  <span v-if="row.sex === 2">女</span>
                </template>
              </el-table-column>
              <el-table-column label="年龄下限值" align="center" prop="ageLowerLimit" width="120"></el-table-column>
              <el-table-column label="年龄上限值" align="center" prop="ageUpperLimit" width="120"></el-table-column>
              <el-table-column label="检测项下限值" align="center" prop="checkLowerLimit" width="120"></el-table-column>
              <el-table-column label="检测项上限值" align="center" prop="checkUpperLimit" width="120"></el-table-column>
              <el-table-column label="检测项单位" align="center" prop="checkUnit" width="120"></el-table-column>
              <el-table-column label="生效日期" align="center" prop="takeEffectTime"></el-table-column>
              <el-table-column label="失效日期" align="center" prop="invalidTime"></el-table-column>
            </el-table>

            <div style="margin-top: 12px">
              <div v-show="checkedNum !== 0" style="float: left">
                <el-button size="mini" type="danger" round @click="handleCancellation()"
                >作废{{ checkedNum }}条</el-button
                >
                <el-button size="mini" type="warning" round @click="handleLoseEfficacy()"
                >失效{{ checkedNum }}条</el-button
                >
              </div>

              <el-pagination
                style="float: right"
                layout="total,sizes, prev, pager, next"
                @size-change="handleSizeChange($event, pageParamsOne)"
                @current-change="handleCurrentChange($event, pageParamsOne)"
                :current-page="pageParamsOne.pageNo"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageParamsOne.pageSize"
                :total="pageParamsOne.total"
              >
              </el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="已废弃" name="1">
            <el-table :data="tableDataTwo">
              <el-table-column label="#" align="center" width="50" type="index"></el-table-column>
              <el-table-column label="中心编号" align="center" prop="coreCode"></el-table-column>
              <el-table-column label="中心名称" align="center" prop="coreName"></el-table-column>
              <el-table-column label="实验室编号" align="center" prop="labCode" width="120"></el-table-column>
              <el-table-column label="实验室名称" align="center" prop="labName" width="120"></el-table-column>
              <el-table-column label="模块名称编码" align="center" prop="moduleCode" width="120"></el-table-column>
              <el-table-column label="模块名称" align="center" prop="moduleName"></el-table-column>
              <el-table-column label="检测项编码" align="center" prop="checkCode" width="120"></el-table-column>
              <el-table-column label="检测项" align="center" prop="checkProName"></el-table-column>
              <el-table-column label="性别" align="center" prop="sex">
                <template v-slot="{ row }">
                  <span v-if="row.sex === 0">未知</span>
                  <span v-if="row.sex === 1">男</span>
                  <span v-if="row.sex === 2">女</span>
                </template>
              </el-table-column>
              <el-table-column label="年龄下限值" align="center" prop="ageLowerLimit" width="120"></el-table-column>
              <el-table-column label="年龄上限值" align="center" prop="ageUpperLimit" width="120"></el-table-column>
              <el-table-column label="检测项下限值" align="center" prop="checkLowerLimit" width="120"></el-table-column>
              <el-table-column label="检测项上限值" align="center" prop="checkUpperLimit" width="120"></el-table-column>
              <el-table-column label="检测项单位" align="center" prop="checkUnit" width="120"></el-table-column>
              <el-table-column label="生效日期" align="center" prop="takeEffectTime"></el-table-column>
              <el-table-column label="失效日期" align="center" prop="invalidTime"></el-table-column>
            </el-table>
            <el-row style="margin-top: 12px" type="flex" justify="end">
              <el-pagination
                layout="total,sizes, prev, pager, next"
                @size-change="handleSizeChange($event, pageParamsTwo)"
                @current-change="handleCurrentChange($event, pageParamsTwo)"
                :current-page="pageParamsTwo.pageNo"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageParamsTwo.pageSize"
                :total="pageParamsTwo.total"
              >
              </el-pagination>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="已失效" name="2">
            <el-table :data="tableDataThree">
              <el-table-column label="#" align="center" width="50" type="index"></el-table-column>
              <el-table-column label="中心编号" align="center" prop="coreCode"></el-table-column>
              <el-table-column label="中心名称" align="center" prop="coreName"></el-table-column>
              <el-table-column label="实验室编号" align="center" prop="labCode" width="120"></el-table-column>
              <el-table-column label="实验室名称" align="center" prop="labName" width="120"></el-table-column>
              <el-table-column label="模块名称编码" align="center" prop="moduleCode" width="120"></el-table-column>
              <el-table-column label="模块名称" align="center" prop="moduleName"></el-table-column>
              <el-table-column label="检测项编码" align="center" prop="checkCode" width="120"></el-table-column>
              <el-table-column label="检测项" align="center" prop="checkProName"></el-table-column>
              <el-table-column label="性别" align="center" prop="sex">
                <template v-slot="{ row }">
                  <span v-if="row.sex === 0">未知</span>
                  <span v-if="row.sex === 1">男</span>
                  <span v-if="row.sex === 2">女</span>
                </template>
              </el-table-column>
              <el-table-column label="年龄下限值" align="center" prop="ageLowerLimit" width="120"></el-table-column>
              <el-table-column label="年龄上限值" align="center" prop="ageUpperLimit" width="120"></el-table-column>
              <el-table-column label="检测项下限值" align="center" prop="checkLowerLimit" width="120"></el-table-column>
              <el-table-column label="检测项上限值" align="center" prop="checkUpperLimit" width="120"></el-table-column>
              <el-table-column label="检测项单位" align="center" prop="checkUnit" width="120"></el-table-column>
              <el-table-column label="生效日期" align="center" prop="takeEffectTime"></el-table-column>
              <el-table-column label="失效日期" align="center" prop="invalidTime"></el-table-column>
            </el-table>
            <el-row style="margin-top: 12px" type="flex" justify="end">
              <el-pagination
                layout="total,sizes, prev, pager, next"
                @size-change="handleSizeChange($event, pageParamsThree)"
                @current-change="handleCurrentChange($event, pageParamsThree)"
                :current-page="pageParamsThree.pageNo"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageParamsThree.pageSize"
                :total="pageParamsThree.total"
              >
              </el-pagination>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <!-- 弹窗 -->
    <el-dialog @close="handleCancel()" :visible="addDiaVis" title="实验室正常值管理" width="800px">
      <el-form label-width="110px" ref="addFormRef" :model="addFormData" :rules="addFormRules">
        <el-row>
          <el-col :span="12" v-for="item in addFormColumns" :key="item.prop">
            <el-form-item :label="item.label" :prop="item.prop">
              <!-- 下拉框 -->
              <el-select
                @change="onFormCoreNameChange($event, item)"
                size="mini"
                clearable
                style="width: 90%"
                v-if="item.ele === 'select'"
                v-model="addFormData[item.valueProp]"
              >
                <el-option v-for="it in item.options" :key="it.value" :label="it.label" :value="it.value"></el-option>
              </el-select>
              <!-- 输入框 -->
              <el-input
                size="mini"
                style="width: 90%"
                v-if="item.ele === 'input'"
                v-model="addFormData[item.valueProp]"
                :disabled="item.disabled"
              ></el-input>
              <!-- 时间选择器 -->
              <el-date-picker
                value-format="yyyy-MM-dd"
                size="mini"
                style="width: 90%"
                v-if="item.ele === 'datePicker'"
                v-model="addFormData[item.valueProp]"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="handleCancel()">取消</el-button>
        <el-button type="primary" size="mini" @click="btnSubmit()">提交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { handleExportResponse } from '@/utils/index'
export default {
  data() {
    return {
      formColumns: [
        { ele: 'select', label: '中心名称：', prop: 'coreId', options: [] },
        { ele: 'selectMut', label: '实验室名称：', prop: 'labIds', options: [] },
      ],
      formData: {
        labIds: [],
        coreId: '',
      },
      activeName: '0',
      tableDataOne: [],
      tableDataTwo: [],
      tableDataThree: [],
      pageParamsOne: {
        pageNo: 1,
        pageSize: 10,
        total: null,
      },
      pageParamsTwo: {
        pageNo: 1,
        pageSize: 10,
        total: null,
      },
      pageParamsThree: {
        pageNo: 1,
        pageSize: 10,
        total: null,
      },
      // 最全的实验室下拉项
      originalCoreOptions: [],
      addDiaVis: false,
      // 💭弹窗表单规则
      addFormColumns: [
        { ele: 'select', label: '中心名称：', prop: 'coreId', valueProp: 'coreId', disabled: false, options: [] },
        { ele: 'input', label: '中心编号：', prop: 'coreCode', valueProp: 'coreCode', disabled: true },
        { ele: 'select', label: '实验室名称：', prop: 'labId', valueProp: 'labId', disabled: false, options: [] },
        { ele: 'input', label: '实验室编号：', prop: 'labCode', valueProp: 'labCode', disabled: true },
        {
          ele: 'select',
          label: '模块名称：',
          prop: 'moduleCode',
          valueProp: 'moduleCode',
          disabled: false,
          options: [],
        },
        { ele: 'input', label: '模块名称编码：', prop: 'moduleCodeCode', valueProp: 'moduleCode', disabled: true },
        {
          ele: 'select',
          label: '检查项名称：',
          prop: 'checkCode',
          valueProp: 'checkCode',
          disabled: false,
          options: [],
        },
        { ele: 'input', label: '检查项编码：', prop: 'checkCodeCode', valueProp: 'checkCode', disabled: true },
        {
          ele: 'select',
          label: '性别：',
          prop: 'sex',
          valueProp: 'sex',
          disabled: false,
          options: [
            { label: '男', value: 1 },
            { label: '女', value: 2 },
            { label: '未知', value: 0 },
          ],
        },
        { ele: 'input', label: '性别编码值：', prop: 'sexCode', valueProp: 'sex', disabled: true },
        { ele: 'input', label: '年龄下限值：', prop: 'ageLowerLimit', valueProp: 'ageLowerLimit', disabled: false },
        { ele: 'input', label: '年龄上限值：', prop: 'ageUpperLimit', valueProp: 'ageUpperLimit', disabled: false },
        {
          ele: 'input',
          label: '检查项下限值：',
          prop: 'checkLowerLimit',
          valueProp: 'checkLowerLimit',
          disabled: false,
        },
        {
          ele: 'input',
          label: '检查项上限值：',
          prop: 'checkUpperLimit',
          valueProp: 'checkUpperLimit',
          disabled: false,
        },
        { ele: 'input', label: '检查项单位：', prop: 'checkUnit', valueProp: 'checkUnit', disabled: false },
        {
          ele: 'datePicker',
          label: '生效日期：',
          prop: 'takeEffectTime',
          valueProp: 'takeEffectTime',
          disabled: false,
        },
        { ele: 'datePicker', label: '失效日期：', prop: 'invalidTime', valueProp: 'invalidTime', disabled: false },
      ],
      // 弹窗表单数据
      addFormData: {},
      defaultAddFormData: {
        coreId: '',
        labId: '',
        moduleCode: '',
        checkCode: '',
        sex: '',
        ageLowerLimit: '',
        ageUpperLimit: '',
        checkLowerLimit: '',
        checkUpperLimit: '',
        checkUnit: '',
        takeEffectTime: '',
        invalidTime: '',
      },
      // 弹窗表单规则
      addFormRules: {
        coreId: [
          {
            required: true,
            message: '请选择',
            trigger: 'blur',
          },
        ],
        checkCode: [{
          required: true,
          message: '请选择',
          trigger: 'blur',
        }],
        labId: [
          {
            required: true,
            message: '请选择',
            trigger: 'blur',
          },
        ],
        moduleCode: [
          {
            required: true,
            message: '请选择',
            trigger: 'blur',
          },
        ],
        checkUnit: [
          {
            required: true,
            message: '请选择',
            trigger: 'blur',
          },
        ],
        takeEffectTime: [
          {
            required: true,
            message: '请选择',
            trigger: 'blur',
          },
        ],
      },
      // 表格选中的数量
      checkedNum: 0,
      checkedIds: [],
      diaIsAdd: true,
      editId: '',
      projectId: '',
      projectDatabaseId: '',
      databaseId: '',
      originalLabOptions: '',
      databaseVersion: '',
      environment: '',
      importLoading: false,
      fileList: [],
    }
  },
  created() {
    this.projectId = localStorage.getItem('sys-project-id') || ''
    this.projectDatabaseId = localStorage.getItem('project-database-Id') || ''
    this.environment = localStorage.getItem('environment') || ''
    this.getCenterNameOptions()
    this.getCentral()
    this.getReferenceValue()
  },
  methods: {
    ...mapActions('centralManagement', [
      'getCentralListAPI',
      'getCentralLabAPI',
      'getReferenceValueAPI',
      'getModuleNameAPI',
      'addLabReferenceAPI',
      'getCheckOptionsAPI',
      'deleteLabReferenceAPI',
      'isWasteLabReferenceAPI',
      'updateLabReferenceAPI',
      'exportLaboratoryInfoAPI',
      'downloadTemplateAPI',
      'importLaboratoryInfoAPI',
    ]),
    ...mapActions('subjectInformation', ['getUpdateSubjectInfo']),
    // 下载导入模板
    handleDownLoad() {
      this.downloadTemplateAPI().then(res => {
        const { data } = res
        handleExportResponse(data, '实验室参考值_导入模板')
      })
    },
    // 导入
    handleImportEmbeddedEncoding(file) {
      this.importLoading = true
      const formData = new FormData()
      formData.append('file', file.file)
      formData.append('projectId', this.projectId)
      // 导入请求
      this.importLaboratoryInfoAPI({ data: formData })
        .then(res => {
          this.importLoading = false
          if (res.code === 200) {
            this.$message({
              type: 'success',
              message: '导入成功' + res.message,
            })
            this.fileList.push({ name: file.file.name, url: res.data })
            // 获取表格数据
            this.getReferenceValue()
          } else {
            this.$message({
              type: 'error',
              message: '导入数据失败，请稍后重试~',
            })
          }
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    // 导出
    handleDownLoadData() {
      const data = {
        ...this.formData,
        projectId: this.projectId,
        isWaste: Number(this.activeName),
      }
      this.exportLaboratoryInfoAPI({ data }).then(res => {
        const { data } = res
        handleExportResponse(data, '实验室参考值_列表')
      })
    },
    // tab切换
    handleClick(tab, event) {
      this.getReferenceValue()
    },
    // 获取中心名称下拉项和弹窗中心名称的下拉项
    async getCenterNameOptions() {
      const params = {
        projectId: this.projectId,
        projectDatabaseId: this.projectDatabaseId,
      }
      const res = await this.getCentralListAPI({ params })
      const arr = res.data.map(item => {
        return {
          value: item.id,
          label: item.coreName,
        }
      })
      this.formColumns[0].options = arr
      this.addFormColumns[0].options = arr
    },
    // 获取实验室名称下拉项
    async getCentral() {
      const params = {
        projectId: this.projectId,
        projectDatabaseId: this.projectDatabaseId,
        pageNo: 1,
        pageSize: 1000,
      }
      const res = await this.getCentralLabAPI({ params })
      this.originalCoreOptions = res.data.records
    },

    // 中心名称下拉框选择
    onSearchSelectChange(val) {
      const obj = this.originalCoreOptions.find(item => {
        return item.id === val
      })
      this.formColumns[1].options = obj.labList.map(item => {
        return {
          label: item.labName,
          value: item.id,
        }
      })
    },
    // 表单中心名称下拉框选择
    async onFormCoreNameChange(val, item) {
      // 选择中心名称
      if (item.prop === 'coreId') {
        // 筛选中心编号
        const obj = this.originalCoreOptions.find(item => {
          return item.id === val
        })
        this.addFormData.coreCode = obj.coreCode
        // 设置实验室名称下拉项
        this.originalLabOptions = obj.labList
        this.addFormColumns[2].options = obj.labList.map(item => {
          return {
            label: item.labName,
            value: item.id,
          }
        })
        this.getModuleName(val)
      }
      // 选择实验室名称
      if (item.prop === 'labId') {
        const obj = this.originalLabOptions.find(item => {
          return item.id === val
        })
        this.addFormData.labCode = obj.labCode
      }
      // 选择模块名称
      if (item.prop === 'moduleCode') {
        const params = {
          projectId: this.projectId,
          projectDatabaseId: this.projectDatabaseId,
          databaseId: this.databaseId,
          code_name: val,
          databaseVersion: this.databaseVersion,
          environment: this.environment,
        }
        const res = await this.getCheckOptionsAPI({ params })
        const arr = res.data.map(item => {
          return {
            label: item.codeDescribe,
            value: item.codeValue,
          }
        })
        this.addFormColumns[6].options = arr
      }
    },
    // 获取表单模块名称下拉项
    async getModuleName(coreId) {
      // 获取useVersion
      const paramsTwo = { projectId: this.projectId, projectDatabaseId: this.projectDatabaseId, coreId: coreId }
      const result = await this.getUpdateSubjectInfo({ params: paramsTwo })
      if (result.data.length !== 0) {
        const obj = result.data.find(item => item.coreId === coreId)
        this.databaseVersion = obj.useVersion
        this.databaseId = obj.databaseId
      }
      const params = {
        projectId: this.projectId,
        projectDatabaseId: this.projectDatabaseId,
        databaseId: this.databaseId,
        databaseVersion: this.databaseVersion,
        code_name: 'LBCAT',
      }
      const res = await this.getModuleNameAPI({ params })
      const arr = res.data.map(item => {
        return {
          label: item.codeDescribe,
          value: item.codeValue,
        }
      })
      this.addFormColumns[4].options = arr
    },

    // 获取表格数据
    async getReferenceValue() {
      let pageParamsP = {}
      // 不同的tab页，页码参数
      if (this.activeName === '0') {
        pageParamsP = this.pageParamsOne
      } else if (this.activeName === '1') {
        pageParamsP = this.pageParamsTwo
      } else if (this.activeName === '2') {
        pageParamsP = this.pageParamsThree
      }
      const data = {
        projectId: this.projectId,
        projectDatabaseId: this.projectDatabaseId,
        ...this.formData,
        isWaste: Number(this.activeName),
        ...pageParamsP,
      }
      const res = await this.getReferenceValueAPI({ data })
      res.data.records.sort((a, b) => a.coreCode - b.coreCode)
      // 复制页面的total
      if (this.activeName === '0') {
        this.tableDataOne = res.data.records
        this.pageParamsOne.total = res.data.total
      } else if (this.activeName === '1') {
        this.tableDataTwo = res.data.records
        this.pageParamsTwo.total = res.data.total
      } else if (this.activeName === '2') {
        this.tableDataThree = res.data.records
        this.pageParamsThree.total = res.data.total
      }
      this.pageParamsOne.total = res.data.total
    },
    publicClose() {
      this.$refs.addFormRef.resetFields()
      this.addDiaVis = false
    },
    // 表单提交
    async btnSubmit() {
      await this.$refs.addFormRef.validate()
      if (this.diaIsAdd) {
        const data = {
          projectId: this.projectId,
          projectDatabaseId: this.projectDatabaseId,
          ...this.addFormData,
        }
        const res = await this.addLabReferenceAPI({ data })
        if (res.code === 200) {
          this.$message.success('新增成功')
          this.publicClose()
          this.getReferenceValue()
        }
      } else {
        const data = {
          projectId: this.projectId,
          projectDatabaseId: this.projectDatabaseId,
          ...this.addFormData,
          id: this.editId,
        }
        const res = await this.updateLabReferenceAPI({ data })
        if (res.code === 200) {
          this.$message.success('修改成功！')
          this.publicClose()
          this.getReferenceValue()
        }
      }
    },
    // 表单取消
    handleCancel() {
      this.publicClose()
    },
    // 页码改变
    handleSizeChange(val, pageParams) {
      pageParams.pageSize = val
      this.getReferenceValue()
    },
    handleCurrentChange(val, pageParams) {
      pageParams.pageNo = val
      this.getReferenceValue()
    },
    handleSearch() {
      if (this.activeName === '0') {
        this.pageParamsOne.pageNo = 1
        this.pageParamsOne.pageSize = 10
      } else if (this.activeName === '1') {
        this.pageParamsTwo.pageNo = 1
        this.pageParamsTwo.pageSize = 10
      } else if (this.activeName === '2') {
        this.pageParamsThree.pageNo = 1
        this.pageParamsThree.pageSize = 10
      }

      this.getReferenceValue()
    },
    handleReset() {
      this.formData.labIds = []
      this.formData.coreId = ''
      this.getReferenceValue()
    },
    handleAdd() {
      this.addDiaVis = true
      this.diaIsAdd = true
    },

    // 编辑
    async handleEdit(row) {
      this.editId = row.id
      this.diaIsAdd = false
      this.addDiaVis = true
      this.addFormData = {
        ...row,
      }
      this.onFormCoreNameChange(this.addFormData.coreId, { prop: 'coreId' })
      this.onFormCoreNameChange(this.addFormData.moduleCode, { prop: 'moduleCode' })
    },
    // 删除
    async handleDelete(row) {
      const data = {
        ids: [row.id],
      }
      const res = await this.deleteLabReferenceAPI({ data })
      if (res.code === 200) {
        this.$message.success('删除成功')
        this.getReferenceValue()
      }
    },
    // 表格选择
    handleTableOneSelect(val) {
      this.checkedNum = val.length
      this.checkedIds = val.map(item => {
        return item.id
      })
    },
    // 作废
    async handleCancellation() {
      const data = {
        ids: this.checkedIds,
        isWaste: 1,
      }
      const res = await this.isWasteLabReferenceAPI({ data })
      if (res.code === 200) {
        this.$message.success('作废成功')
        this.getReferenceValue()
      }
    },
    // 失效
    async handleLoseEfficacy() {
      const data = {
        ids: this.checkedIds,
        isWaste: 2,
      }
      const res = await this.isWasteLabReferenceAPI({ data })
      if (res.code === 200) {
        this.$message.success('失效成功')
        this.getReferenceValue()
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.lab_reference_wrapper {
  background-color: $white;
  height: calc(100% - 24px);
  padding: 12px;
}
</style>
